package com.halflife.concurrence;

public class PromiseTest {
    public volatile boolean isDone = false;
    public void await() throws InterruptedException {
        synchronized (this) {
            while (!this.isDone) {
                wait();
            }
        }
    }
    public PromiseTest sycnHandle() throws InterruptedException {
        Thread.currentThread().sleep(2*1000);
        this.isDone = true;
        synchronized (this) {
            notifyAll();
        }

        return this;
    }

    public static void main(String[] args) {
        PromiseTest t = new PromiseTest();
        Thread thread1 = new Thread(()->{
            try {
                t.sycnHandle();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
        Thread thread2 = new Thread(()->{
            try {
                t.await();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("asdfasfdasdf");
        });
        thread1.start();
        thread2.start();
        while (true) {

        }
    }

}
